/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle csq-3@163.com
 * @since : 2015-08-20 22:01:21
 * @filengrasse : src/config.js
 * @version : 
 * @description : 
 */

    var config = {},
         domain = window.location.origin;

    if (window.location.href.indexOf("?dev") > 0) {
        console.log('dev');
        config.mainSite = 'http://www.grass.com',
        config.remoteUrl = 'http://static.grass.com',
        config.apiUrl = domain+'/apis/',
        config.apiAccessUrl = domain+'/apis/s'+getCookie('session_id')+'/',
        config.locale = getLocale();
    } else if (window.location.href.indexOf("?test") > 0) {
        console.log('test');
        config.mainSite = 'http://www.grass.com',
        config.remoteUrl = 'http://static.grass.com',
        config.apiUrl = domain+'/apis/',
        config.apiAccessUrl = domain+'/apis/s'+getCookie('session_id')+'/',
        config.locale = getLocale();
    } else {
        console.log('prod');
        config.mainSite = 'http://www.grass.com',
        config.remoteUrl = 'http://static.grass.com',
        config.apiUrl = domain+'/apis/',
        config.apiAccessUrl = domain+'/apis/s'+getCookie('session_id')+'/',
        config.locale = getLocale();
    }

    function getLocale(){
        var locale = getCookie('siteLocale');
        return locale == '' ? 'en' : local;
    };

    function getCookie(ngrasse) {
        var search = ngrasse + "=",offset,end; 
        if(document.cookie.length > 0) { 
            offset = document.cookie.indexOf(search);
            if(offset != -1) { 
                offset += search.length;
                end = document.cookie.indexOf(";", offset); 
                if(end == -1) {
                    end = document.cookie.length;
                };
                return decodeURI(document.cookie.substring(offset, end));
            } 
        }
        return "";
    };

    module.exports = config;

